// 记录布局组件的一些状态
import { defineStore } from "pinia";
import { ref } from "vue";

export const useLayoutStore = defineStore('layout', () => {  
  // 展开的菜单项
  const menuOpened = ref(new Set<string>());
  // 菜单滚动条位置
  const scrollTop = ref(0);

  const setMenuOpened = (index: string) => {
    menuOpened.value.add(index);
  };

  const delMenuOpened = (index: string) => {
    menuOpened.value.delete(index);
  };

  const clearMenuOpened = () => {
    menuOpened.value.clear();
  };

  const setScrollTop = (top: number) => {
    scrollTop.value = top;
  };

  // 用于退出系统时的清理
  const clear = () => {
    clearMenuOpened();
    setScrollTop(0);
  };

  return {
     menuOpened, scrollTop, setMenuOpened, setScrollTop, clearMenuOpened, clear, delMenuOpened
  }
});

